Feeling

Feelings Table

Feelings at time of assessment

Feeling Strongly Disagree Disagree Neutral Agree Strongly Agree
Happy 53 127 386 557 267
Frustrated 267 564 299 201 59
Sad 286 634 292 129 49
Worried 257 512 282 266 73
Restless 268 519 327 234 42
Excited 68 325 532 296 169
Calm 53 171 444 504 218
Lonely 290 543 281 146 130
Bored 296 568 354 142 30
Sluggish 224 475 279 317 95

Feelings Charts

Location

Location Table

Location at time of assessment

Location No Yes
Bus, Train, or Vehicle 1308 82
Church 1363 27
Home 330 1060
Friend’s or Relative’s House 1295 95
Store / Mall 1365 25
Outdoors 1276 114
Other 1311 79
Restaurant 1386 4
School / Library 1390 0
Work 1368 22

Location Charts

Activity

Activity Table

Activity at time of assessment

Activity No Yes
Interacting With Someone 1035 355
Sitting 723 667
Sleeping 1097 293
Standing 1196 194
Talking 1127 263
Walking / Excercising 1281 109
Other 1146 244

Activity Charts

Physical Activity

Table Row

Physical activity yesterday (Yes / No)

Activity No Yes
Walked or Biked to Get Somewhere 780 610
Engaged in Physical Fitness 1163 227
Engaged in Physical Activity at Work or Home 710 680
Did None of These 1016 374
Used Pedometer 1330 60

Physical activity yesterday (Minutes)

Activity 10 Minutes or Less 11-20 Minutes 21-30 Minutes 31-40 Minutes 41-50 Minutes More than 50 Minutes
Walked or Biked to Get Somewhere 44 112 182 134 53 85
Engaged in Physical Fitness 12 20 47 57 44 47
Engaged in Physical Activity at Work or Home 24 60 129 181 114 172

Sitting time yesterday

4 or fewer hours More than 4 hours- 6 hours More than 6 hours- 8 hours More than 8 hours- 10 hours More than 10 hours - 12 hours More than 12 hours
338 341 312 244 106 49

Physical Activity Charts

Diet

Table Row

Ate any yesterday (Yes / No)

Food No Yes
Fruit 435 955
Vegetables 272 1118
Sugar-Sweetened Beverages 462 928
Deserts and Other Sweets 608 782
Red Meat or Processed Meat 420 970

Servings ate yesterday

Food 0 Servings 1 Serving 2 Servings 3 Servings 4 Servings 5 or More Servings
Fruit 435 401 375 136 38 5
Vegetables 272 476 423 175 36 8
Sugar-Sweetened Beverages 462 311 216 182 72 147
Deserts and Other Sweets 608 459 195 96 24 8
Red Meat or Processed Meat 420 446 393 114 15 2

Diet Charts

Medication

Freetime

Interaction

Substances

Substances Plot

Session Info

#> R version 3.3.0 (2016-05-03)
#> Platform: x86_64-apple-darwin13.4.0 (64-bit)
#> Running under: OS X 10.11.4 (El Capitan)
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] dataclean_0.1.0     ggplot2_2.1.0       knitr_1.13         
#> [4] dplyr_0.4.3         flexdashboard_0.2.0
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_0.12.5      magrittr_1.5     munsell_0.4.3    colorspace_1.2-6
#>  [5] R6_2.1.2         highr_0.6        stringr_1.0.0    plyr_1.8.3      
#>  [9] tools_3.3.0      parallel_3.3.0   grid_3.3.0       gtable_0.2.0    
#> [13] DBI_0.4-1        htmltools_0.3.5  yaml_2.1.13      lazyeval_0.1.10 
#> [17] assertthat_0.1   digest_0.6.9     formatR_1.4      evaluate_0.9    
#> [21] rmarkdown_0.9.6  labeling_0.3     stringi_1.0-1    scales_0.4.0    
#> [25] jsonlite_0.9.20
---
title: "Exploratory Analysis of Daily EMA Data"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: scroll
    source: embed
---

```{r setup, include=FALSE}
# Setup options
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")

# CRAN packages
library(flexdashboard)
library(dplyr)
library(knitr)
library(ggplot2)

# devtools::install_github("mbcann01/dataclean")
library(dataclean)

# Load data
load("/Users/bradcannell/Dropbox/Research/mChat/data/daily_april_2016.RData")

# Sort by case number and date
daily <- dplyr::arrange(daily, case_number, date)
```

Overview {.sidebar}
===============================================================================

Here we plot the aggregate unconditional distribution of responses for each of the following variables:

1. Feelings at time of assessment

2. Location at time of assessment

3. Activity at time of assessment

4. Physical activity yesterday

5. Diet yesterday

6. Medication use yesterday

7. Freetime activities yesterday

8. Meaningful Interaction yesterday

9. Substance use yesterday




Feeling
===============================================================================

Feelings Table
-------------------------------------------------------------------------------

### Feelings at time of assessment

```{r feeling_table}
x <- select(daily, happy, frustrated, sad, worried, restless, excited, calm, lonely, bored, sluggish)

vars = tools::toTitleCase(names(x)) # Title case labels

df <- data.frame(
  x1 = vars,
  x2 = NA,
  x3 = NA,
  x4 = NA,
  x5 = NA,
  x6 = NA,
  stringsAsFactors = FALSE
)

i <- 1
for (var in x) {
  resp_table <- table(var)
  resp <- as.vector(resp_table)
  df$x2[i] <- resp[1]
  df$x3[i] <- resp[2]
  df$x4[i] <- resp[3]
  df$x5[i] <- resp[4]
  df$x6[i] <- resp[5]
  i <- i + 1
}

names(df) <- c("Feeling", "Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree")

kable(df)
```

Feelings Charts
-------------------------------------------------------------------------------

```{r plot_emotions}
for (var in vars) {
  plot <- ggplot(daily, aes_string(x = tolower(var))) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle(paste("I Feel", var, "Right Now")) +
    theme_bw()
  print(plot)
}
```




Location
===============================================================================

Location Table
-------------------------------------------------------------------------------

### Location at time of assessment

```{r location_table}
x <- select(daily, bus_loc, church_loc, home_loc, frifam_loc, store_loc, outdoors_loc, other_loc, restaurant_loc, school_loc, work_loc)

loc <- c("Bus, Train, or Vehicle", "Church", "Home", "Friend's or Relative's House", "Store / Mall", "Outdoors", "Other", "Restaurant", "School / Library", "Work")

df <- data.frame(
  x1 = loc,
  x2 = NA,
  x3 = NA,
  stringsAsFactors = FALSE
)

i <- 1
for (var in x) {
  resp_table <- table(var)
  resp <- as.vector(resp_table)
  df$x2[i] <- resp[1]
  df$x3[i] <- resp[2]
  i <- i + 1
}

names(df) <- c("Location", "No", "Yes")

kable(df)
```

Location Charts
-------------------------------------------------------------------------------

```{r plot_location}
x <- names(x)
i <- 1
for (var in x) {
  plot <- ggplot(daily, aes_string(x = var)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle(paste("Location at Time of Assessment:", loc[i])) +
    theme_bw()
  print(plot)
  i <- i + 1
}
```




Activity
===============================================================================

Activity Table
-------------------------------------------------------------------------------

### Activity at time of assessment

```{r activity_table}
x <- select(daily, pre_who, sit_act, sleep_act, stand_act, talk_act, walk_act, other_act)

act <- c("Interacting With Someone", "Sitting", "Sleeping", "Standing", "Talking", "Walking / Excercising", "Other")

df <- data.frame(
  x1 = act,
  x2 = NA,
  x3 = NA,
  stringsAsFactors = FALSE
)

i <- 1
for (var in x) {
  resp_table <- table(var)
  resp <- as.vector(resp_table)
  df$x2[i] <- resp[1]
  df$x3[i] <- resp[2]
  i <- i + 1
}

names(df) <- c("Activity", "No", "Yes")

kable(df)
```

Activity Charts
-------------------------------------------------------------------------------

```{r plot_act}
x <- names(x)
i <- 1
for (var in x) {
  plot <- ggplot(daily, aes_string(x = var)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle(paste(act[i], "Right Before the Phone Rang")) +
    theme_bw()
  print(plot)
  i <- i + 1
}
```




Physical Activity
===============================================================================

Table Row {.tabset .tabset-fade}
-------------------------------------------------------------------------------

### Physical activity yesterday (Yes / No)

```{r physact_table_1}
x <- select(daily, bike_yest, run_yest, cleaning_yest, none_yest, pedometer)

act <- c("Walked or Biked to Get Somewhere", "Engaged in Physical Fitness", "Engaged in Physical Activity at Work or Home", "Did None of These", "Used Pedometer")

df <- data.frame(
  x1 = act,
  x2 = NA,
  x3 = NA,
  stringsAsFactors = FALSE
)

i <- 1
for (var in x) {
  resp_table <- table(var)
  resp <- as.vector(resp_table)
  df$x2[i] <- resp[1]
  df$x3[i] <- resp[2]
  i <- i + 1
}

names(df) <- c("Activity", "No", "Yes")

kable(df)
```

### Physical activity yesterday (Minutes)

```{r physact_table_2}
x <- select(daily, min_walk, min_run, min_act)

act <- c("Walked or Biked to Get Somewhere", "Engaged in Physical Fitness", "Engaged in Physical Activity at Work or Home")

df <- data.frame(
  x1 = act,
  x2 = NA,
  x3 = NA,
  x4 = NA,
  x5 = NA,
  x6 = NA,
  x7 = NA,
  stringsAsFactors = FALSE
)

i <- 1
for (var in x) {
  resp_table <- table(var)
  resp <- as.vector(resp_table)
  df$x2[i] <- resp[1]
  df$x3[i] <- resp[2]
  df$x4[i] <- resp[3]
  df$x5[i] <- resp[4]
  df$x6[i] <- resp[5]
  df$x7[i] <- resp[6]
  i <- i + 1
}

names(df) <- c("Activity", "10 Minutes or Less", "11-20 Minutes", "21-30 Minutes", "31-40 Minutes", "41-50 Minutes", "More than 50 Minutes")

kable(df)
```

### Sitting time yesterday

```{r sitting_table}
df <- data.frame(
  x1 = NA,
  x2 = NA,
  x3 = NA,
  x4 = NA,
  x5 = NA,
  x6 = NA,
  stringsAsFactors = FALSE
)

resp_table <- table(daily$min_sit)
resp <- as.vector(resp_table)
df$x1 <- resp[1]
df$x2 <- resp[2]
df$x3 <- resp[3]
df$x4 <- resp[4]
df$x5 <- resp[5]
df$x6 <- resp[6]

names(df) <- c("4 or fewer hours", "More than 4 hours- 6 hours", "More than 6 hours- 8 hours", "More than 8 hours- 10 hours", "More than 10 hours - 12 hours", "More than 12 hours")

kable(df)
```

Physical Activity Charts
-------------------------------------------------------------------------------

```{r plot_act_yest}
x <- names(select(daily, bike_yest, run_yest, cleaning_yest, none_yest, pedometer, min_walk, min_run, min_act, min_sit))
act <- c("Walked or Biked to Get Somewhere", "Engaged in Physical Fitness", "Engaged in Physical Activity at Work or Home", "Did None of These", "Used Pedometer", "Walked or Biked to Get Somewhere", "Engaged in Physical Fitness", "Engaged in Physical Activity at Work or Home", "Sat")
i <- 1
for (var in x) {
  plot <- ggplot(daily, aes_string(x = var)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle(paste(act[i], "Yesterday")) +
    theme_bw() +
    if (i > 5) {
      theme(axis.text.x = element_text(angle = 45, vjust = 0.5))
    } else {
      theme()
    }
  print(plot)
  i <- i + 1
}

# Plot steps
ggplot(daily, aes(x = steps)) +
  geom_histogram(binwidth = 1000) +
  scale_x_continuous("") +
  ggtitle("Steps Yesterday") +
  theme_bw()
```




Diet
===============================================================================

Table Row {.tabset .tabset-fade}
-------------------------------------------------------------------------------

### Ate any yesterday (Yes / No)

```{r diet_table_1}
x <- select(daily, any_fruit, any_veg, any_ssb, any_sweets, any_meat)

food <- c("Fruit", "Vegetables", "Sugar-Sweetened Beverages", "Deserts and Other Sweets", "Red Meat or Processed Meat")

df <- data.frame(
  x1 = food,
  x2 = NA,
  x3 = NA,
  stringsAsFactors = FALSE
)

i <- 1
for (var in x) {
  resp_table <- table(var)
  resp <- as.vector(resp_table)
  df$x2[i] <- resp[1]
  df$x3[i] <- resp[2]
  i <- i + 1
}

names(df) <- c("Food", "No", "Yes")

kable(df)
```

### Servings ate yesterday

```{r diet_table_2}
x <- select(daily, serv_fruit, serv_veg, serv_ssb, serv_sweets, serv_meat)

food <- c("Fruit", "Vegetables", "Sugar-Sweetened Beverages", "Deserts and Other Sweets", "Red Meat or Processed Meat")

df <- data.frame(
  x1 = food,
  x2 = NA,
  x3 = NA,
  x4 = NA,
  x5 = NA,
  x6 = NA,
  x7 = NA,
  stringsAsFactors = FALSE
)

i <- 1
for (var in x) {
  resp_table <- table(var)
  resp <- as.vector(resp_table)
  df$x2[i] <- resp[1]
  df$x3[i] <- resp[2]
  df$x4[i] <- resp[3]
  df$x5[i] <- resp[4]
  df$x6[i] <- resp[5]
  df$x7[i] <- resp[6]
  i <- i + 1
}

names(df) <- c("Food", "0 Servings", "1 Serving", "2 Servings", "3 Servings", "4 Servings", "5 or More Servings")

kable(df)
```

Diet Charts
-------------------------------------------------------------------------------

```{r diet_yest}
x <- names(select(daily, any_fruit, any_veg, any_ssb, any_sweets, any_meat, serv_fruit, serv_veg, serv_ssb, serv_sweets, serv_meat))

food <- c("Fruit", "Vegetables", "Sugar-Sweetened Beverages", "Deserts and Other Sweets", "Red Meat or Processed Meat", "Fruit", "Vegetables", "Sugar-Sweetened Beverages", "Deserts and Other Sweets", "Red Meat or Processed Meat")

i <- 1
for (var in x) {
  plot <- ggplot(daily, aes_string(x = var)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle(paste("Ate", food[i], "Yesterday")) +
    theme_bw() +
    theme()
  print(plot)
  i <- i + 1
}
```




Medication
===============================================================================




Freetime
===============================================================================




Interaction
===============================================================================




Substances
===============================================================================

Substances Plot
-------------------------------------------------------------------------------

```{r plot_sub_yest}
x <- names(select(daily, alc_sub, cig_sub, mar_sub, opi_sub, stim_sub, herb_sub, other_sub, none_sub))
sub <- c("Alcohol", "Tobacco", "Marijuana", "Opiates", "Stimulants", "Herbal Drugs", "Another drug", "No Substances")
i <- 1
for (var in x) {
  plot <- ggplot(daily, aes_string(x = var)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle(paste("Participant used", sub[i], "Yesterday")) +
    theme_bw()
  print(plot)
  i <- i + 1
}
```




Session Info
===============================================================================
```{r session_info, echo=FALSE}
sessionInfo()
```